package blog.action;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import blog.entity.Article;
import blog.entity.Comment;
import blog.entity.Link;
import blog.entity.Notice;
import blog.enums.ArticleStatus;
import blog.enums.LinkStatus;
import blog.enums.NoticeStatus;
import blog.service.ArticleService;
import blog.service.CommentService;
import blog.service.LinkService;
import blog.service.NoticeService;

@Controller
public class TagAction {
	// 文章信息
		@Resource
		private ArticleService articleService;

		// 评论信息
		@Resource
		private CommentService commentService;

		// 友情链接
		@Resource
		private LinkService linkService;

		// 公告
		@Resource
		private NoticeService noticeService;
		@RequestMapping(value = "/tag/{tagId}")
		public String index(@PathVariable("tagId") Integer tagId,
				@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
				@RequestParam(required = false, defaultValue = "10") Integer pageSize, ModelMap m) {
			HashMap<String, Object> paramMap = new HashMap<>(1);
			paramMap.put("status", ArticleStatus.PUBLISH.getValue());
			paramMap.put("tagId",tagId);

			// 文章列表
			PageInfo<Article> articleList = articleService.getPageArticleList(pageIndex, pageSize, paramMap);
			m.put("pageInfo", articleList);
			m.put("pageUrlPrefix", "/tag/"+tagId+"?pageIndex");

			// 最新评论
			List<Comment> recentCommentList = commentService.listRecentComment(10);
			m.put("recentCommentList", recentCommentList);

			// 友情链接(在framework.jsp中做的显示)
			List<Link> linkList = linkService.listLink(LinkStatus.NORMAL.getValue());
			m.put("linkList", linkList);

			// 公告
			List<Notice> noticeList = noticeService.listNotice(NoticeStatus.NORMAL.getValue());
			m.put("noticeList", noticeList);

			return "index";
		}
}
